package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.entity.AssetType;
import com.project.service.AssetTypeService;
import com.project.util.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资产类别控制器
 *
 * @author Leo高洋
 * @create 2023-01-18 1:35
 */
@RestController
@RequestMapping("/assetType")
public class AssetTypeController {
    @Autowired
    private AssetTypeService assetTypeService;

    private final static Logger logger = LoggerFactory.getLogger(AssetTypeController.class);

    /**
     * 查询全部资产类别信息
     *
     * @return
     */
    @GetMapping("/list")
    public R list() {
        logger.info("全部资产类别信息");
        List<AssetType> assetTypeList = assetTypeService.getAll();
        Map<String, Object> map = new HashMap<>();
        map.put("assetTypeList", assetTypeList);
        return R.ok(map);
    }

    @PostMapping("/listByName")
    public R listByName(@RequestParam("name") String name) {
        List<AssetType> assetTypeList = assetTypeService.list(new QueryWrapper<AssetType>().like("name", name));
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("assetTypeList", assetTypeList);
        return R.ok(resultMap);
    }
}
